package com.gcxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.gcxy.dto.clazz.ClazzInfoDTO;
import com.gcxy.dto.clazz.GetClazzListDTO;
import com.gcxy.entity.Clazz;
import com.gcxy.service.ClazzService;
import com.gcxy.mapper.ClazzMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gcxy.utils.BeanCopyUtil;
import com.gcxy.vo.clazz.ClazzVO;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 班级 服务实现类
 * </p>
 *
 * @author Huang先森
 * @since 2024-07-22
 */
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {

    @Resource
    private ClazzMapper clazzMapper;

    /**
     * 根据班级名称获取班级信息
     *
     * @param name
     * @return
     */
    public Clazz getClazzInfoByName(String name) {
        LambdaQueryWrapper<Clazz> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Clazz::getClassName, name);
        Clazz clazz = getOne(queryWrapper);
        return ObjectUtils.isEmpty(clazz) ? null : clazz;
    }

    /**
     * 新建班级
     *
     * @param clazzInfoDTO
     * @return
     */
    @Override
    public Integer insertClazzInfo(ClazzInfoDTO clazzInfoDTO) {
        Clazz clazz = BeanCopyUtil.copy(clazzInfoDTO, Clazz.class);
        int row = clazzMapper.insert(clazz);
        return row;
    }

    /**
     * 根据条件获取班级列表
     *
     * @param getClazzListDTO
     * @return
     */
    @Override
    public List<ClazzVO> getClazzListByCondition(GetClazzListDTO getClazzListDTO) {
        return clazzMapper.getClazzListByCondition(getClazzListDTO);
    }

}
